﻿using System;
using System.Collections.Generic;
using System.Text;

namespace iPdf
{
    class MergePage : TataRibbonPage
    {
        public override bool OrderMatters
        {
            get
            {
                return true;
            }
        }

        public override bool ReadyToAct
        {
            get
            {
                return Global.Grid.RowsCount > 2;
            }
        }

        public override string IntroInfo
        {
            get
            {
                return global::iPdf.Properties.Resources.MergePageIntroInfo;
            }
        }

        public MergePage()
            : base()
        {
            visibleColumns.Add(TataGrid.Password);
            visibleColumns.Add(TataGrid.From);
            visibleColumns.Add(TataGrid.To);
            visibleColumns.Add(TataGrid.Bookmark);

            actor = new PdfMerger();
        }

        protected override ActionItem GetIthActionItem(TataGrid grid, int i)
        {
            SourceGrid.Cells.Cell sourceCell = (SourceGrid.Cells.Cell)grid[i, TataGrid.Source.Index];
            SourceGrid.Cells.Cell fromCell = (SourceGrid.Cells.Cell)grid[i, TataGrid.From.Index];
            SourceGrid.Cells.Cell toCell = (SourceGrid.Cells.Cell)grid[i, TataGrid.To.Index];

            MergeItem item = new MergeItem();
            item.Source = (string)grid.GetColumnValueAtRow(i, TataGrid.Source);
            item.Password = (PasswordString)grid.GetColumnValueAtRow(i, TataGrid.Password);
            item.Bookmark = (bool)grid.GetColumnValueAtRow(i, TataGrid.Bookmark);
            try
            {
                item.From = (int)grid.GetColumnValueAtRow(i, TataGrid.From);
                item.To = (int)grid.GetColumnValueAtRow(i, TataGrid.To);
            }
            catch
            {
                item.From = 0;
                item.To = 0;
            }

            return item;
        }

    }
}
